package com.cskaoyan.controller.admincontroller;

import com.cskaoyan.bean.po.MarketBrand;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.adminservice.BrandService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:J
 * @datetime 2022/12/29 21:14
 * @description: TODO:
 * 商品品牌 信息表
 */
@RestController
@RequestMapping("admin/brand")
public class BrandController {
//http://182.92.235.201:8083/admin/brand/list?page=1&limit=20&sort=add_time&order=desc
    @Autowired
    BrandService brandService;
    //list?page=1&limit=20&sort=add_time&order=desc
    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo pageInfo,Integer id,String name){
        //TODO：所以这个id谁指定？
        CommonData<MarketBrand> data=brandService.list(pageInfo,id,name);
        return BaseRespVo.okYa(data);

    }

    /**
     * 增加品牌
     * http://182.92.235.201:8083/admin/storage/create
     * http://182.92.235.201:8083/admin/brand/create
     * @param marketBrand
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketBrand marketBrand){
        BaseRespVo createBrand=brandService.create(marketBrand);
        return createBrand;
    }

    /**
     * 请求 URL: http://182.92.235.201:8083/admin/brand/update
     * post
     * @param marketBrand
     * @return
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketBrand marketBrand){
        BaseRespVo updateBrand=brandService.update(marketBrand);
        return updateBrand.ok();
    }

    /**
     * http://182.92.235.201:8083/admin/brand/delete
     * @param marketBrand
     * @return
     */
    @RequiresPermissions("admin:brand:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketBrand marketBrand){
        BaseRespVo deleteBrand=brandService.delete(marketBrand);
        return deleteBrand;
    }
}
